﻿using SharpGL;
using System;
namespace MutsiEngine
{
    public class Billboard : MoveableObject
    {
        public Mesh mesh;
        private double[] modelview = new double[16];

        int posName = 0;
        int timeName = 0;

        public Vector3 target = new Vector3((float)Math.PI / 2f, 0, 0);

        public Billboard()
        {
            this.Name = "Billboard";
            mesh = Primitives.FrontFacePlane(new Vector3(0, 0, -1), 0.2f);
            position.Y = 0.2f;
        }

        public virtual void Update(Vector3 cameraEuler)
        {
        }

        public virtual void Draw(GameTime gameTime, OpenGL gl, uint shaderProgram)
        {
            gl.PushMatrix();

            if (posName == 0)
            {
                posName = gl.GetUniformLocation(shaderProgram, "pos");
                gl.Uniform3(posName, position.X, position.Y, position.Z);
                timeName = gl.GetUniformLocation(shaderProgram, "time");
            }
            gl.Uniform1(timeName, gameTime.TotalTime.ElapsedMilliseconds);
            


            /*gl.GetDouble(OpenGL.GL_MODELVIEW_MATRIX, modelview);

            modelview[0] = 1;
            modelview[1] = 0;
            modelview[2] = 0;

            modelview[4] = 0;
            modelview[5] = 1;
            modelview[6] = 0;

            modelview[8] = 0;
            modelview[9] = 0;
            modelview[10] = -1;
            


            gl.LoadMatrix(modelview);*/
            gl.Translate(position.X, position.Y, position.Z);
            gl.Rotate(target.Y, 0, 1, 0);
            mesh.Draw(gl);

            gl.PopMatrix();
        }
    }
}
